package com.practice.java8中双冒号方法引用如何使用;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * @program: tenghw-practice-demo
 * @author: tenghw
 * @create: 2024-01-06 14:07
 * @Version 1.0
 * @description: 测试 对象::普通方法
 **/
public class Demo1 {
    public void printString(String str) {
        System.out.println("~~~："+str);
    }
    public  Integer printString1(String str) {
        try {
            System.out.println("待解析为整数的字符串为：" + str);
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            System.out.println("字符串无法解析为整数：" + str);
            return 0;
        }
    }
    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        List<String> list=new ArrayList<String>(){{
            add("teng");
            add("hh");
            add("ww");
        }};
        //list.stream().forEach(item->demo1.printString(item));
        list.stream().forEach(demo1::printString);//::对上一行Lambda的进一步简化

        List<String> list1 = Arrays.asList("1", "2", "ss");
        //list1.stream().forEach(item->demo1.printString1(item));
        list1.stream().forEach(demo1::printString1);
    }
}